package com.sanjiahantang.youjiarole.module.login.beans;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.sanjiahantang.youjiarole.base.BaseBean;

import java.util.List;

/**
 * Created by zy on 2017/9/29.
 */

public class LoginBean extends BaseBean {


    /**
     * "code": 1003,
     "session": {
     "errorCount": 0,
     "ipStr": "172.16.60.31",
     "lastErrorTime": "2017-10-11T15:03:21.948",
     "lastLoginTime": "2017-10-11T14:58:57",
     "loginTypeId": "0",
     "phone": "18822185396",
     "token": "6f9b5952da9fb870fa1396dd205b37a7",
     "userSessionDto": {
     "expiredTime": "2017-10-11T15:54:22.301",
     "phone": "18822185396",
     "token": "6f9b5952da9fb870fa1396dd205b37a7",
     "userName": "高牛逼"
     }
     },
     "message": "登录成功"
     */
    private String data;

    public Data getData() {
        return new Gson().fromJson(data,Data.class);
    }

    public void setData(String data) {
        this.data = data;
    }

    public static class Data{
        private long code;
        private Session session;
        private String message;

        public long getCode() {
            return code;
        }

        public void setCode(long code) {
            this.code = code;
        }

        public Session getSession() {
            return session;
        }

        public void setSession(Session session) {
            this.session = session;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }

    public static class Session{
        private int errorCount;
        private String ipStr;
        private String lastErrorTime;
        private String lastLoginTime;
        private String loginTypeId;
        private String phone;
        private String token;
        private Dto userSessionDto;


        public int getErrorCount() {
            return errorCount;
        }

        public void setErrorCount(int errorCount) {
            this.errorCount = errorCount;
        }

        public String getIpStr() {
            return ipStr;
        }

        public void setIpStr(String ipStr) {
            this.ipStr = ipStr;
        }

        public String getLastErrorTime() {
            return lastErrorTime;
        }

        public void setLastErrorTime(String lastErrorTime) {
            this.lastErrorTime = lastErrorTime;
        }

        public String getLastLoginTime() {
            return lastLoginTime;
        }

        public void setLastLoginTime(String lastLoginTime) {
            this.lastLoginTime = lastLoginTime;
        }

        public String getLoginTypeId() {
            return loginTypeId;
        }

        public void setLoginTypeId(String loginTypeId) {
            this.loginTypeId = loginTypeId;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        public Dto getUserSessionDto() {
            return userSessionDto;
        }

        public void setUserSessionDto(Dto userSessionDto) {
            this.userSessionDto = userSessionDto;
        }
    }

    public static class Dto{
        private String expiredTime;
        private String phone;
        private String userName;
        /*private int[] roleList;

        public int[] getRoleList() {
            return roleList;
        }

        public void setRoleList(int[] roleList) {
            this.roleList = roleList;
        }

        public String getRoleId(){
            if (roleList == null || roleList.length == 0){
                return "";
            }
            String roleId = "";
            for (int i = 0;i < roleList.length;i++){
                roleId += roleList[i] + ",";
            }
            roleId = roleId.substring(0,roleId.length() - 1);
            return roleId;
        }*/

        private List<Role> roleList;

        public List<Role> getRoleList() {
            return roleList;
        }

        public String getRoleId(){
            if (roleList == null || roleList.size() == 0){
                return "";
            }
            String roleId = "";
            for (int i = 0;i < roleList.size();i++){
                if (roleList.get(i).getRoleState() == 2){
                    roleId += roleList.get(i).getRoleId() + ",";
                }

            }
            if (!TextUtils.isEmpty(roleId) && roleId.length() > 0){
                roleId = roleId.substring(0,roleId.length() - 1);
            }

            return roleId;
        }


        //1未通过 0 审核中 2 通过
        public int getRoleState(){
            int state = 1;
            for (int i = 0;i < roleList.size();i++){
                if (roleList.get(i).getRoleState() == 2){
                    state = 2;
                    break;
                }else if (roleList.get(i).getRoleState() == 0){
                    state = 0;
                }
            }
            return state;
        }

        public void setRoleList(List<Role> roleList) {
            this.roleList = roleList;
        }

        public String getExpiredTime() {
            return expiredTime;
        }

        public void setExpiredTime(String expiredTime) {
            this.expiredTime = expiredTime;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }
    }

    public static class Role{
        private int roleId;
        private int roleState;

        public int getRoleId() {
            return roleId;
        }

        public void setRoleId(int roleId) {
            this.roleId = roleId;
        }

        public int getRoleState() {
            return roleState;
        }

        public void setRoleState(int roleState) {
            this.roleState = roleState;
        }
    }
}
